﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class User_CourseDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Check user role
        if(Session["Userrole"] != null)
        {
            int userrole = Int32.Parse((String)Session["Userrole"]);
            switch (userrole)
            {
                case Global.TEACHER_ROLE:
                case Global.STUDENT_ROLE:
                    btnEditCourse.Visible = false;
                    btnDel.Visible = false;
                    break;
                case Global.ADMIN_ROLE:
                    btnEditCourse.Visible = true;
                    btnDel.Visible = true;
                    break;
            }
        }
        else
        {
            btnEditCourse.Visible = false;
            btnDel.Visible = false;
        }
        ViewCourseDetail();
    }

    public void ViewCourseDetail()
    {
        String courseID = "";
        if (Session["CourseID"] != null)
        {
            courseID = (String)Session["CourseID"];
        }

        DataSourceSelectArguments sc = new DataSourceSelectArguments();
        SqlDataSource1.SelectCommand = "Select * from Courses where id = '" + courseID + "'";
        DataView dv = (DataView)SqlDataSource1.Select(sc);

        if (dv.Count != 0)
        {
            hf_id.Value = dv[0][0].ToString();
            lblNameDetails.Text = dv[0][1].ToString();
            lblName.Text = dv[0][1].ToString();
            lblTeacher.Text = dv[0][4].ToString();
            lblStartDate.Text = dv[0][2].ToString();
            lblEndDate.Text = dv[0][3].ToString();
            lblCost.Text = dv[0][5].ToString();
            lblDescription.Text = dv[0][6].ToString();
        }
    }

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }
    protected void Del_Click(object sender, EventArgs e)
    {
        int id = Int32.Parse(hf_id.Value);
        SqlDataSource1.DeleteCommand = "delete from courses where id = "+id;
        SqlDataSource1.Delete();
        
    }
}